package com.zx.ishopping.controller.User;


import com.zx.ishopping.VO.AddressVO;
import com.zx.ishopping.entity.Address;
import com.zx.ishopping.results.Result;
import com.zx.ishopping.services.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地址控制器
 */
@RestController
@RequestMapping("/user/address")
public class AddressController {

    @Autowired
    private AddressService addressService;
    
    /**
     * 获取地址列表
     * @return
     */
    @GetMapping("/getAddress")
    public Result<List<AddressVO>> getAddress(){
        List<AddressVO> addressVOList = addressService.getAddress();
        
    	return Result.success(addressVOList);
    }


    /**
     * 添加地址
     * @param address
     * @return
     */
    @PostMapping("/addAddress")
    public Result addAddress(@RequestBody Address  address){
    addressService.addAddress(address);
    return Result.success();
    }


    /**
     * 删除地址
     */
    @DeleteMapping("/deleteAddress")
    public Result deleteAddress(Long id){
        addressService.deleteAddress(id);
        return Result.success();
    }

    /**
     * 修改地址
     * @param address
     * @return
     */
    @PutMapping("/updateAddress")
    public Result updateAddress(@RequestBody Address address){
    	addressService.updateAddress(address);
    	return Result.success();
    }

}
